package com.xbongbong.pro.statistic.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.saas.enums.DetailTabEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 全景图枚举
 * @author zcp
 * @version v1.0
 * @date 2019/5/29 15:22
 * @since v1.0
 */
@Getter
public enum PanoramaEnum {
    /**
     * 客户全景图相关，以“CUSTOMER_”开头
     * ["100_01_01", "100_01_02", "100_01_03", "100_01_04", "100_01_05", "100_02_01", "100_02_02", "100_03_01", "100_03_02", "100_03_03", "100_03_04", "100_03_05", "100_03_06", "100_04_01", "100_04_02"]
     */
    //跟进相关
    CUSTOMER_COMMUNICATE_ADD(PanoramaTeamEnum.CUSTOMER_COMMUNICATE.getCode() + "_01", "enum.panorama.name.customer_communicate_add", "enum.panorama.unit.customer_communicate_add", XbbRefTypeEnum.CUSTOMER_COMMUNICATE, PanoramaTeamEnum.CUSTOMER_COMMUNICATE, true, DetailTabEnum.COMMUNICATE_RECORD),
    //未跟进时长，一般为n天，但是未联系时直接显示“未联系”
    CUSTOMER_FORGET(PanoramaTeamEnum.CUSTOMER_COMMUNICATE.getCode() + "_02", "enum.panorama.name.customer_forget", "", XbbRefTypeEnum.CUSTOMER_MANAGEMENT, PanoramaTeamEnum.CUSTOMER_COMMUNICATE, false, null),
    CUSTOMER_CALL_COUNT(PanoramaTeamEnum.CUSTOMER_COMMUNICATE.getCode() + "_03", "enum.panorama.name.customer_call_count", "enum.panorama.unit.customer_communicate_add", XbbRefTypeEnum.CALL_CENTER, PanoramaTeamEnum.CUSTOMER_COMMUNICATE, true, DetailTabEnum.CALL_LOG),
    //通话时长需要格式化为 h时m分
    CUSTOMER_CALL_LOG_TIME(PanoramaTeamEnum.CUSTOMER_COMMUNICATE.getCode() + "_04", "enum.panorama.name.customer_call_log_time", "", XbbRefTypeEnum.CALL_CENTER, PanoramaTeamEnum.CUSTOMER_COMMUNICATE, false, DetailTabEnum.CALL_LOG),
    CUSTOMER_CALL_LOG_TIME_RATE(PanoramaTeamEnum.CUSTOMER_COMMUNICATE.getCode() + "_05", "enum.panorama.name.customer_call_log_time_rate", "", XbbRefTypeEnum.CALL_CENTER, PanoramaTeamEnum.CUSTOMER_COMMUNICATE, false, DetailTabEnum.CALL_LOG),

    //机会相关
    CUSTOMER_OPPORTUNITY_COUNT(PanoramaTeamEnum.CUSTOMER_OPPORTUNITY.getCode() + "_01", "enum.panorama.name.customer_opportunity_count", "enum.panorama.unit.customer_opportunity_count", XbbRefTypeEnum.SALES_OPPORTUNITY, PanoramaTeamEnum.CUSTOMER_OPPORTUNITY, true, DetailTabEnum.SALE_OPPORTUNITY),
    CUSTOMER_OPPORTUNITY_AMOUNT(PanoramaTeamEnum.CUSTOMER_OPPORTUNITY.getCode() + "_02", "enum.panorama.name.customer_opportunity_amount", "enum.panorama.unit.customer_opportunity_amount", XbbRefTypeEnum.SALES_OPPORTUNITY, PanoramaTeamEnum.CUSTOMER_OPPORTUNITY, true, DetailTabEnum.SALE_OPPORTUNITY),

    //报价单
    CUSTOMER_QUOTATION_COUNT(PanoramaTeamEnum.CUSTOMER_QUOTATION.getCode() + "_01", "enum.panorama.name.customer_quotation_count", "enum.panorama.unit.customer_opportunity_count", XbbRefTypeEnum.QUOTATION, PanoramaTeamEnum.CUSTOMER_QUOTATION, true, DetailTabEnum.CUSTOMER_QUOTATION),
    CUSTOMER_QUOTATION_AMOUNT(PanoramaTeamEnum.CUSTOMER_QUOTATION.getCode() + "_02", "enum.panorama.name.customer_quotation_amount", "enum.panorama.unit.customer_opportunity_amount", XbbRefTypeEnum.QUOTATION, PanoramaTeamEnum.CUSTOMER_QUOTATION, true, DetailTabEnum.CUSTOMER_QUOTATION),

    //合同回款相关
    CUSTOMER_CONTRACT_COUNT(PanoramaTeamEnum.CUSTOMER_CONTRACT.getCode() + "_01", "enum.panorama.name.customer_contract_count", "enum.panorama.unit.customer_contract_count", XbbRefTypeEnum.CONTRACT, PanoramaTeamEnum.CUSTOMER_CONTRACT, true, DetailTabEnum.CONTRACT_TAB),
    CUSTOMER_CONTRACT_AMOUNT(PanoramaTeamEnum.CUSTOMER_CONTRACT.getCode() + "_02", "enum.panorama.name.customer_contract_amount", "enum.panorama.unit.customer_opportunity_amount", XbbRefTypeEnum.CONTRACT, PanoramaTeamEnum.CUSTOMER_CONTRACT, true, DetailTabEnum.CONTRACT_TAB),
    CUSTOMER_PAYMENT_ED(PanoramaTeamEnum.CUSTOMER_CONTRACT.getCode() + "_03", "enum.panorama.name.customer_payment_ed", "enum.panorama.unit.customer_opportunity_amount", XbbRefTypeEnum.PAYMENT_MANAGEMENT, PanoramaTeamEnum.CUSTOMER_CONTRACT, true, DetailTabEnum.PAYMENT_MANAGEMENT),
    CUSTOMER_PREPAYMENT_BALANCE(PanoramaTeamEnum.CUSTOMER_CONTRACT.getCode() + "_07", "enum.panorama.name.customer_prepayment_balance", "enum.panorama.unit.customer_opportunity_amount", XbbRefTypeEnum.PAYMENT_MANAGEMENT, PanoramaTeamEnum.CUSTOMER_CONTRACT, true, DetailTabEnum.PAYMENT_MANAGEMENT),
    CUSTOMER_BALANCE_RECEIVABLE(PanoramaTeamEnum.CUSTOMER_CONTRACT.getCode() + "_10", "enum.panorama.name.customer_balance_receivable","enum.panorama.unit.customer_opportunity_amount",XbbRefTypeEnum.PAYMENT_MANAGEMENT,PanoramaTeamEnum.CUSTOMER_CONTRACT,true,DetailTabEnum.PAYMENT_MANAGEMENT),
    CUSTOMER_PAYMENT_RED(PanoramaTeamEnum.CUSTOMER_CONTRACT.getCode() + "_05", "enum.panorama.name.customer_payment_red", "enum.panorama.unit.customer_contract_amount", XbbRefTypeEnum.PAYMENT_MANAGEMENT, PanoramaTeamEnum.CUSTOMER_CONTRACT, true, DetailTabEnum.PAYMENT_MANAGEMENT),
    CUSTOMER_PAYMENT_BAD(PanoramaTeamEnum.CUSTOMER_CONTRACT.getCode() + "_06", "enum.panorama.name.customer_payment_bad", "enum.panorama.unit.customer_contract_amount", XbbRefTypeEnum.PAYMENT_MANAGEMENT, PanoramaTeamEnum.CUSTOMER_CONTRACT, true, DetailTabEnum.PAYMENT_MANAGEMENT),
    CUSTOMER_INVOICE_AMOUNT(PanoramaTeamEnum.CUSTOMER_CONTRACT.getCode() + "_08", "enum.panorama.name.customer_invoice_amount", "enum.panorama.unit.customer_contract_amount", XbbRefTypeEnum.PAYMENT_MANAGEMENT, PanoramaTeamEnum.CUSTOMER_CONTRACT, true, DetailTabEnum.INVOICE_HISTORY),

    //成交行为相关
    CUSTOMER_CONTRACT_CYCLE(PanoramaTeamEnum.CUSTOMER_OK.getCode() + "_01", "enum.panorama.name.customer_contract_cycle", "enum.panorama.unit.customer_contract_cycle", XbbRefTypeEnum.CONTRACT, PanoramaTeamEnum.CUSTOMER_OK, false, DetailTabEnum.CONTRACT_TAB),
    CUSTOMER_CONTRACT_TIME_LAST(PanoramaTeamEnum.CUSTOMER_OK.getCode() + "_02", "enum.panorama.name.customer_contract_time_last", "enum.panorama.unit.customer_contract_time_last", XbbRefTypeEnum.CONTRACT, PanoramaTeamEnum.CUSTOMER_OK, false, DetailTabEnum.CONTRACT_TAB),

    UNKNOWN("404", "enum.panorama.name.unknown", "", XbbRefTypeEnum.UNKNOWN, PanoramaTeamEnum.UNKNOWN, false, null),
    ;
    /**
     * 唯一标识
     */
    private String code;
    /**
     * 全景指标名称
     */
    private String name;
    /**
     * 指标单位
     */
    private String unit;
    /**
     * 业务类型
     */
    private XbbRefTypeEnum xbbRefTypeEnum;
    /**
     * 指标所属分组
     */
    private PanoramaTeamEnum panoramaTeamEnum;
    /**
     * 是否可以跳转
     */
    private boolean jump;
    /**
     * 全景指标穿透到详情页的其他tab，根据jump控制是否能跳转
     */
    private DetailTabEnum detailTabEnum;

    PanoramaEnum(String code, String name, String unit, XbbRefTypeEnum xbbRefTypeEnum, PanoramaTeamEnum panoramaTeamEnum, boolean jump, DetailTabEnum detailTabEnum) {
        this.code = code;
        this.name = name;
        this.unit = unit;
        this.xbbRefTypeEnum = xbbRefTypeEnum;
        this.panoramaTeamEnum = panoramaTeamEnum;
        this.jump = jump;
        this.detailTabEnum = detailTabEnum;
    }

    /**
     * 通过枚举<code>code</code>获得枚举
     *
     * @param code
     * @return SystemCodeEnum
     */
    public static PanoramaEnum getByCode(String code) {
        for (PanoramaEnum cache : values()) {
            if (Objects.equals(cache.code, code)) {
                return cache;
            }
        }
        return UNKNOWN;
    }

    /**
     * 根据分组获取该分组下面的全景指标
     * @param PanoramaTeamEnum 指标分组枚举
     * @return java.util.List<com.xbongbong.pro.statistic.enums.PanoramaEnum>
     * @author zcp
     * @date 2019/5/30 16:07
     * @version v1.0
     * @since v1.0
     */
    public static List<PanoramaEnum> getByTeam(PanoramaTeamEnum PanoramaTeamEnum) {
        List<PanoramaEnum> list = new ArrayList<>();
        for (PanoramaEnum cache : values()) {
            if (Objects.equals(cache.panoramaTeamEnum, PanoramaTeamEnum)) {
                list.add(cache);
            }
        }
        return list;
    }

    /**
     * 根据code数组，获取全景指标枚举数组
     * @param codeIn 全景指标code数组
     * @return java.util.List<com.xbongbong.pro.statistic.enums.PanoramaEnum>
     * @author zcp
     * @date 2019/6/3 9:19
     * @since v1.0
     * @version v1.0
     */
    public static List<PanoramaEnum> getByCodeIn(List<String> codeIn) {
        List<PanoramaEnum> list = new ArrayList<>();
        if (codeIn == null) {
            return list;
        }
        for (PanoramaEnum cache : values()) {
            if (codeIn.contains(cache.code)) {
                list.add(cache);
            }
        }
        return list;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

    public String getUnit() {
        return I18nMessageUtil.getMessage(unit);
    }
}
